package com.weapp.system;

import com.weapp.common.utils.RedisUtils;
import com.weapp.system.constant.CacheConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author jsy
 * @description: project start af ter init function
 * @date 2022/7/1 15:27
 */
@Component
public class WeAppStartupRunner implements CommandLineRunner {

  private static final Logger logger = LoggerFactory.getLogger(WeAppStartupRunner.class);
  @Autowired
  private RedisUtils redisUtils;

  @Override
  public void run(String... args) {
    try {
      System.out.println(">>>>>>>>>>>>>>>" + WeAppStartupRunner.class.getName() + "<<<<<<<<<<<<<");
//      System.out.println(">>>>>>>>>>>>>>>服务启动执行，请您耐心等待<<<<<<<<<<<<<");
//      initFunction();
//      System.out.println(">>>>>>>>>>>>>>>服务启动完毕，初始化数据完成进入系统<<<<<<<<<<<<<");
    } catch (Exception e) {
      logger.error("初始化方法:{}异常，请检查异常数据:{}", WeAppStartupRunner.logger.getName(), e);
    }
  }

  private void initFunction() {
    System.out.println(">>>>>>>>>>>>>>>JsyStartupRunner.initFunction() 执行start <<<<<<<<<<<<<");
    Set<Object> keys = redisUtils.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
    System.out.println("Login_jwt_keys = " + keys.toString());
    redisUtils.hset(CacheConstants.TEST_KEY + "user", "1111111111111", "1");
    redisUtils.hset(CacheConstants.TEST_KEY + "user", "2222222222222", "2");
    redisUtils.hset(CacheConstants.TEST_KEY + "user", "3333333333333", "3");
    System.out.println("redisCache.keys(CacheConstants.TEST_KEY+\"*\") = " + redisUtils.keys(CacheConstants.TEST_KEY + "*"));
    Object hget = redisUtils.hget(CacheConstants.TEST_KEY + "user", "1111111111111");
    Object hget1 = redisUtils.hget(CacheConstants.TEST_KEY + "user", "2222222222222");
    System.out.println("hget = " + hget);
    System.out.println("hget1 = " + hget1);
    System.out.println(">>>>>>>>>>>>>>>JsyStartupRunner.initFunction() 执行end <<<<<<<<<<<<<");
  }

}
